package LeetCode.exercise;

import java.util.ArrayList;
import java.util.TreeSet;

public class LC128 {
    public int longestConsecutive(int[] nums) {
        if(nums.length == 1 || nums.length == 0){
            return nums.length;
        }
        TreeSet<Integer> set = new TreeSet<>();
        for(int i : nums){
            set.add(i);
        }
        ArrayList<Integer> list = new ArrayList<>(set);
        int res = 1;
        for(int i = 1; i < list.size(); i++){
            int count = 1;
            while(i < list.size() && list.get(i) - list.get(i-1) == 1){
                count++;
                i++;
            }
            res = Math.max(res, count);
        }
        return res;
    }
}
